<template>
    <div class="cashier-bill">
        <div class="list">
            <div class="search-part">
                <div class="part1">
                    <el-row :gutter="20">
                        <el-col :span="5">
                            <div class="pd10">
                                <button type="button" class="circleBtn purpleBtn" :class="[getCurrentPurple]" @click="queryState3()">
                                    <span>全部</span>
                                </button>
                                <button type="button" class="circleBtn blueBtn" :class="[getCurrentBlue]" @click="queryState0()">
                                    <span>挂单</span>
                                </button>
                                <button type="button" class="circleBtn yellowBtn" :class="[getCurrentYellow]" @click="queryState2()">
                                    <span>完成</span>
                                </button>
                            </div>
                        </el-col>
                        <el-col :span="7">
                            <div class="grid-content">
                                <v-search @transferParam="getParam"></v-search>
                            </div>
                        </el-col>
                        <el-col :span="10">
                            <div class="grid-content pdt10 btns">
                                <el-button class="red-btn" @click="cashier()"> 下 单 </el-button>
                                <lodop-com :getLodopInstance="showDialog" :fromPage="billType" style="padding-left:9px;display: inline-block"></lodop-com>
                            </div>
                        </el-col>
                    </el-row>
                </div>
            </div>
        </div>
        <div class="list-main">
            <waterfall :line-gap="300" :watch="items" id="myDIV"
                       :max-line-gap="360"
                       :min-line-gap="220"
                       :fixed-height="true"
                       align="center">
                <!-- each component is wrapped by a waterfall slot -->
                <waterfall-slot
                        v-for="(item, index) in items"
                        :width="item.width"
                        :height="item.height"
                        :order="index"
                        :key="item.id"

                >
                    <transition name="el-zoom-in-center" mode="out-in">


                        <v-billcomp
                                :item="item"
                                :classText="getState(item.state)"
                                :index="index"
                                :backSelectItems="selectItems"
                                class="item"
                                :backItems="getCurrentSelectItems"
                                :viewClick="function(){info(item)}"
                                :buttonText="buttonText"
                                :isMutpart="false"
                                :currentRadio="currentRadio"

                        >
                            <h6 class="sn">{{item.sn}}</h6>

                            <ul>
                                <!--<li><span content="Top Left 提示文字">{{item.memberName || '非会员'}} </span></li>-->
                                <li>
                              <span class="l1">
                                <el-tooltip class="item spec" effect="dark" content="消费会员" placement="right">
                                  <el-button>{{item.memberName || '非会员'}}</el-button>
                                </el-tooltip>
                              </span>
                                </li>
                                <li class="credit" v-if="item.state == 1">
                                    <span class="span1">实收</span>
                                    <span class="amount">{{Number(item.received || 0).toFixed(2)}}</span>
                                </li>
                                <li class="credit" v-else>
                                    <span class="span1">应收</span>
                                    <span class="amount">{{Number(item.receivable || 0).toFixed(2)}}</span>
                                </li>
                                <li class="bize-date">
                              <span>
                                <el-tooltip class="item spec" effect="dark" content="创建时间" placement="left">
                                  <el-button>{{item.bizdate}}</el-button>
                                </el-tooltip>
                              </span>
                                </li>
                            </ul>

                        </v-billcomp>
                    </transition>

                </waterfall-slot>

            </waterfall>
            <div class="pages">当前第{{currentPage}}页总共{{totalPage}}页</div>
            <div style=" width: 150px; margin: 0 auto;" v-if="allData">没有更多数据了</div>
        </div>
        <el-dialog
                title="提示"
                :visible.sync="dialogVisible"
                size="tiny">
            <span>选择打印样式</span>
            <span slot="footer" class="dialog-footer">
                <el-button @click="print2">票 据</el-button>
                <el-button type="primary" @click="print1">小 票</el-button>
            </span>
        </el-dialog>
    </div>

</template>

<script>
    import Waterfall from 'vue-waterfall/lib/waterfall.vue';
    import WaterfallSlot from 'vue-waterfall/lib/waterfall-slot';
    import vSearch from '../Search.vue';
    import vBillcomp from '../../common/BillComp.vue';
    import moment from 'moment';
    import lodopCom from '../../common/LodopComp.vue';
    export default {
        name: 'keepalive-false',
        data: function () {
            return {
                billType: 'cashier',
                dialogVisible: false,
                currentRadio: {index: -1},
                allData: false,
                allItems: [],
                selectItems: [],
                items: [],
                currentItem: '',
                rows: 20,//显示数量
                page: 1,//当前页数
                totalPage: 1,
                loading: true,
                param: '',
                state: '0,1,2',
                buttonText: '查看',
                currentUser:{},
                top: 10,
                left: 10,
                width: 300,
                height: 20,
                contentFontSize: 10,
                LODOP: "",
                entryModel: []
            }
        },
        computed: {
            currentPage: function () {

                if (this.page < this.totalPage) {

                    return this.page;
                } else {
                    return this.totalPage;
                }
            },
            getCurrentPurple: function () {
                if(this.state == '0'||this.state=='1'||this.state=='2'){
                    return  'purpleBtn'
                }else{
                    return  'purpleActiveBtn'
                }
            },
            getCurrentBlue: function () {
                if(this.state == '0'){
                    return 'blueActiveBtn'
                }else{
                    return 'blueBtn'
                }
            },
            getCurrentYellow: function () {
                if(this.state == '1'){
                    return  'yellowActiveBtn'
                }else{
                    return  'yellowBtn'
                }
            },
        },
        mounted: function () {
            this.currentUser = JSON.parse(localStorage.getItem("currentUser"));
            this.loadMore();
            this.$$("#content").scrollTop(0)
            let self = this;
//            this.rows = Math.floor(self.$$("#content")[0].scrollWidth / 300) * Math.floor(self.$$("#content").innerHeight() / 265)
            this.$$("#content").on('scroll', function (e) {
                var scrollTop = self.$$("#content").scrollTop();
                var innerHeight = self.$$("#content").innerHeight();
                var scrollHeight = self.$$("#content").scrollHeight();
                if (scrollTop + innerHeight >= scrollHeight) {
                    self.page++;
                    if (self.page > self.totalPage) {
                        return;
                    }
                    self.loading = true;
                    self.loadMore();
                    console.log('*(******************' + self.page)
                }
            })


            document.getElementById("myDIV").addEventListener('wheel', function (e) {
                if (e.wheelDelta < 0 && self.$$("#content").scrollTop() === 0) {
                    console.log(e.wheelDelta < 0 && self.$$("#content").scrollTop() === 0)
                    self.page++;
                    self.loading = true;
                    self.loadMore();
                }
            });
        },
        components: {
            vSearch, vBillcomp, Waterfall, WaterfallSlot,lodopCom
        },
        watch: {
            param(val){
                this.items = [];
                this.page = 1;
                this.totalPage = 1;
                this.loading = true;
                this.loadMore();
            },
            state(){
                this.items = [];
                this.page = 1;
                this.totalPage = 1;
                this.loading = true;
                this.loadMore();
            }
        },
        methods: {
            getState: function (state) {
                if (state == 0) {
                    return {
                        'stateClass': 'save-circle',
                        'stateText': '挂单'
                    }
                } else if (state == 1) {
                    return {
                        'stateClass': 'complete-circle',
                        'stateText': '完成'
                    }

                } else {
                    return {
                        'stateClass': 'complete-circle',
                        'stateText': '完成'
                    }

                }
            },
            loadMore() {
                let self = this;
                if (this.page <= this.totalPage && this.loading) {
                    this.$axioxs.get("/sale/?param=" + this.param + "&rows=" + this.rows + "&page=" + this.page + "&states=" + this.state)
                        .then(function (res) {
                                self.totalPage = res.data.totalPage;
                                self.allItems = res.data.records;
                                self.allItems.forEach(item => {
                                    item.bizdate = moment(item.bizdate).format("YYYY-MM-DD HH:mm");
                                    item.height = 186;
                                    item.width = 300;
                                    self.items.push(item);
                                    self.allData = false;
                                });
                                self.loading = false;
                            },
                            (res) => {

                                this.$message({
                                    showClose: true,
                                    type: 'error',
                                    message: res
                                });
                            });
                } else {
                    this.allData = true;
                    this.loading = false;
                }
            },
            getCurrentSelectItems: function (items) {
                console.log("==================>")
                console.log(items)
                // alert(JSON.stringify(items.length))
                this.currentItem = items;
            },
            del(){
                var arr = [];
                let self = this;
                for (var i = 0; i < self.childItem.length; i++) {
                    console.log(self.childItem[i]);
                    self.$axioxs.delete('/sale/' + self.childItem[i].id)
                        .then(function (res) {
                            console.log('删除成功');
                        })
                        .catch(function (error) {
                            console.log(error);
                            self.loading = true;
                        });
                }
                for (var i = 0; i < self.childItem.length; i++) {
                    self.items.splice(self.items.indexOf(self.childItem[i]), 1)
                }
            },
            getParam(res){
                this.param = res;
                this.$$("#content").scrollTop(0)
            },
            queryState0: function () {
//                this.param = "暂存";
                this.state = 0;
            },
            queryState2: function () {
//                this.param = "完成";
                this.state = 1;
            },
            queryState3: function () {
//                this.param = "全部";
                this.state = '0,1,2';
            },
            info: function (item) {
                console.log(item)
                if(item.state == 0){ //挂单
                  let hasRights = this.currentUser.rights.find(obj=> obj === 'sale_unpaid')
                  if(hasRights != 'sale_unpaid'){
                    this.$message({
                        showClose: true,
                        message: '权限不足',
                        type: 'warning'
                    });
                  }else{
                    this.view(item);
                  }
                }
                else {     //查看单据
                  this.view(item);
                }

            },
            view: function (item){
              this.$router.push({
                  name: 'unpaid',
                  path: '/unpaid/settlement',
                  params: {
                      id: item.id,
                      name: item.memberName,
                      memberId: item.memberId,
                      isPayState: item.state,
                      sn: item.sn,
                      item:item
                  }
              });
            },
            cashier: function () {
              let hasRights = this.currentUser.rights.find(obj=> obj === 'sale_paid')
              if(hasRights != 'sale_paid'){
                this.$message({
                    showClose: true,
                    message: '权限不足',
                    type: 'warning'
                });
                return;
              }
                this.$router.push({
                    path: '/cashierProcess'
                });
            },
            ///////////打印////
            showDialog:function(lodopInstance){
                let hasRights = this.currentUser.rights.find(obj=> obj === 'sale_print')
                if(hasRights != 'sale_print'){
                  this.dialogVisible = false;
                }else {
                  this.dialogVisible = true;
                }
                this.LODOP = lodopInstance;

            },
            print1: function () {
                //小票打印
                console.log("小票打印-----")
                let self = this;
                if(this.LODOP!=undefined){
                    this.top = 0;
                    this.left = 5;
                    this.width = 180;
                    this.height = 15;
                    this.contentFontSize = 6;
                    let a = self.currentItem;
                    this.readEntryModel(a,1);
                    this.$on("sale_bill_data_small",this.printSmall);
                    this.dialogVisible = false;
                }else{
                    console.log("无云打印实例")
                    this.dialogVisible = false;
                }
            },
            print2: function () {
                //票据打印
                console.log("票据打印-----")
                if(this.LODOP!=undefined){
                    let self = this;
                    this.top = 10;
                    this.left = 10;
                    this.width = 720;
                    this.height = 25;
                    this.contentFontSize = 15;
                    let a = self.currentItem;
                    this.readEntryModel(a,2);
                    this.$on("sale_bill_data_big",this.printBig);
                    this.dialogVisible = false;
                }else{
                    console.log("无云打印实例")
                    this.dialogVisible = false;
                }
            },
            readEntryModel: function (a,type) {
                console.log("获取分录");
                let self = this;
                this.$axioxs.get("/sale/entry/list?owner=" + a.id).then(
                    function (res) {
                        self.entryModel = res.data;
                        if (type == 1){
                            self.$emit("sale_bill_data_small");
                        }else {
                            self.$emit("sale_bill_data_big");
                        }
                    }
                ).catch(
                    function (error) {
                        console.log(error);
                    }
                );
            },
            printSmall: function () {
                var self = this;
                var a = this.currentItem;
                this.LODOP.PRINT_INIT("");
                //标题
                this.LODOP.SET_PRINT_STYLE("FontSize",this.contentFontSize);
                this.LODOP.SET_PRINT_STYLE("Alignment",2);
                this.LODOP.ADD_PRINT_TEXT(this.top,this.left,this.width,this.height,"销售单");
                this.LODOP.SET_PRINT_STYLEA(1,"Bold",1);
                //头部
                this.LODOP.SET_PRINT_STYLE("Alignment",1);
                this.LODOP.ADD_PRINT_TEXT(this.top=this.top+this.height,this.left,this.width,this.height,"单据编号：" + a.sn );
                this.LODOP.ADD_PRINT_TEXT(this.top=this.top+this.height,this.left,this.width,this.height,"创建日期：" + a.bizdate);
                this.LODOP.ADD_PRINT_TEXT(this.top=this.top+this.height,this.left,this.width,this.height,"单据状态："+ this.getState(a.state).stateText );
                this.LODOP.ADD_PRINT_TEXT(this.top=this.top+this.height,this.left,this.width,this.height,"会员名称：" + a.memberName);
                //内容
                this.top+=this.height;
                this.LODOP.ADD_PRINT_LINE(this.top-5,this.left,this.top-5,this.width+this.left,0,1);  //打印表格横向线
                this.LODOP.SET_PRINT_STYLE("Alignment",2);
                this.LODOP.ADD_PRINT_TEXT(this.top,this.left,this.width/8,this.height*2,"序号");
                this.LODOP.ADD_PRINT_TEXT(this.top,this.left+this.width/8,this.width/8,this.height*2,"名称");
                this.LODOP.ADD_PRINT_TEXT(this.top,this.left+this.width/8*2,this.width/8,this.height*2,"数量");
                this.LODOP.ADD_PRINT_TEXT(this.top,this.left+this.width/8*3,this.width/8,this.height*2,"原价");
                this.LODOP.ADD_PRINT_TEXT(this.top,this.left+this.width/8*4,this.width/8,this.height*2,"单价");
                this.LODOP.ADD_PRINT_TEXT(this.top,this.left+this.width/8*5,this.width/8,this.height*2,"金额");
                this.LODOP.ADD_PRINT_TEXT(this.top,this.left+this.width/8*6,this.width/8,this.height*2,"结算");
                this.LODOP.ADD_PRINT_TEXT(this.top,this.left+this.width/8*7,this.width/8,this.height*2,"备注");

                var iCurLine = this.top+this.height*2;
                let n = 1;
                self.entryModel.forEach(entry => {
                    let payStr = "";
                    switch (entry.payment){
                        case 10:
                            payStr = '扣卡';
                            break;
                        case 20:
                            payStr = '现金';
                            break;
                        case 30:
                            payStr = '积分';
                            break;
                        case 40:
                            payStr = '代金券';
                            break;
                        default:
                            payStr = '无';
                    }
                    this.LODOP.SET_PRINT_STYLE("Alignment",2);
                    this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left,this.width/8,this.height*3,n);
                    this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+this.width/8,this.width/8,this.height*3,entry.goodsName);
                    this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+this.width/8*2,this.width/8,this.height*3,entry.quantity + entry.goodsUnit);
                    this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+this.width/8*3,this.width/8,this.height*3,entry.goodsPrice);
                    this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+this.width/8*4,this.width/8,this.height*3,entry.price);
                    this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+this.width/8*5,this.width/8,this.height*3,entry.amount);
                    this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+this.width/8*6,this.width/8,this.height*3,payStr);
                    this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+this.width/8*7,this.width/8,this.height*3,entry.goodsRemark);
                    iCurLine=iCurLine+this.height*3;
                    n++;
                });

                //底部
                this.LODOP.SET_PRINT_STYLE("Alignment",1);
                this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+5,this.width/3,this.height*2,"应收金额：  " + a.receivable + "元");
                this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+5+this.width/3,this.width/3,this.height*2,"实收金额： " + (a.state==0?"该单未结算":a.received + "元"));
                this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+5+this.width/3*2,this.width/3,this.height*2,"会员余额：" + (a.memberBalance==undefined?"该单未结算":a.memberBalance + "元"));
                this.LODOP.ADD_PRINT_LINE(iCurLine-5,this.left,iCurLine-5,this.width+this.left,0,1);  //打印表格横向线

                iCurLine=iCurLine+this.height*2;
                this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+5,this.width,this.height,"制单人：" + a.creatorName);
                this.LODOP.ADD_PRINT_TEXT(iCurLine+this.height,this.left+5,this.width,this.height*2,"打印日期：" + (new Date()).toLocaleDateString()+" "+(new Date()).toLocaleTimeString());
                this.LODOP.SET_PRINT_PAGESIZE(3,this.width*5,this.height,"");
//                this.LODOP.PREVIEW();
                this.LODOP.PRINT();
            },
            printBig: function () {
                var a = this.currentItem;

                this.LODOP.PRINT_INIT("");
                this.printHeader(a);
                let self = this;
                var iCurLine = this.top+this.height*2;
                var n = 1;
                self.entryModel.forEach(entry => {
                    var payStr = '';
                    switch (entry.payment){
                        case 10:
                            payStr = '扣卡';
                            break;
                        case 20:
                            payStr = '现金';
                            break;
                        case 30:
                            payStr = '积分';
                            break;
                        case 40:
                            payStr = '代金券';
                            break;
                        default:
                            payStr = '无';
                    }
                    if (n!=1 && (n-1)%10==0){
                        this.printfooter(iCurLine,a);
                        this.LODOP.ADD_PRINT_LINE(iCurLine-5,this.left,iCurLine-5,this.width+this.left,0,1);  //打印表格横向线
                        this.LODOP.NewPageA();
                        this.top=10;
                        this.printHeader(a);
                        iCurLine = this.top+this.height*2;
                    }

                    this.LODOP.SET_PRINT_STYLE("Alignment",2);
                    this.LODOP.ADD_PRINT_LINE(iCurLine-5,this.left,iCurLine-5,this.width+this.left,0,1);  //打印表格横向线
                    this.LODOP.ADD_PRINT_LINE(iCurLine-5,this.left,iCurLine+this.height*2-5,this.left,0,1);  //打印表格竖线
                    this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left,this.width/8,this.height*2,n);
                    this.LODOP.ADD_PRINT_LINE(iCurLine-5,this.left+this.width/8,iCurLine+this.height*2-5,this.left+this.width/8,0,1);  //打印表格竖线
                    this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+this.width/8,this.width/8,this.height*2,entry.goodsName);
                    this.LODOP.ADD_PRINT_LINE(iCurLine-5,this.left+this.width/8*2,iCurLine+this.height*2-5,this.left+this.width/8*2,0,1);  //打印表格竖线
                    this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+this.width/8*2,this.width/8,this.height*2,entry.quantity + entry.goodsUnit);
                    this.LODOP.ADD_PRINT_LINE(iCurLine-5,this.left+this.width/8*3,iCurLine+this.height*2-5,this.left+this.width/8*3,0,1);  //打印表格竖线
                    this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+this.width/8*3,this.width/8,this.height*2,entry.goodsPrice);
                    this.LODOP.ADD_PRINT_LINE(iCurLine-5,this.left+this.width/8*4,iCurLine+this.height*2-5,this.left+this.width/8*4,0,1);  //打印表格竖线
                    this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+this.width/8*4,this.width/8,this.height*2,entry.price);
                    this.LODOP.ADD_PRINT_LINE(iCurLine-5,this.left+this.width/8*5,iCurLine+this.height*2-5,this.left+this.width/8*5,0,1);  //打印表格竖线
                    this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+this.width/8*5,this.width/8,this.height*2,entry.amount);
                    this.LODOP.ADD_PRINT_LINE(iCurLine-5,this.left+this.width/8*6,iCurLine+this.height*2-5,this.left+this.width/8*6,0,1);  //打印表格竖线
                    this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+this.width/8*6,this.width/8,this.height*2,payStr);
                    this.LODOP.ADD_PRINT_LINE(iCurLine-5,this.left+this.width/8*7,iCurLine+this.height*2-5,this.left+this.width/8*7,0,1);  //打印表格竖线
                    this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+this.width/8*7,this.width/8,this.height*2,entry.goodsRemark);
                    this.LODOP.ADD_PRINT_LINE(iCurLine-5,this.left+this.width,iCurLine+this.height*2-5,this.left+this.width,0,1);  //打印表格竖线
                    iCurLine=iCurLine+this.height*2;
                    n++;
                });

                n--;
                if ( n%11!=0){
                    for (let i = 0; i < 10-n%10; i++){
                        this.LODOP.ADD_PRINT_LINE(iCurLine-5,this.left,iCurLine-5,this.width+this.left,0,1);  //打印表格横向线
                        this.LODOP.ADD_PRINT_LINE(iCurLine-5,this.left,iCurLine+this.height*2-5,this.left,0,1);  //打印表格竖线
                        this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left,this.width/8,this.height*2,n+i+1);
                        this.LODOP.ADD_PRINT_LINE(iCurLine-5,this.left+this.width/8,iCurLine+this.height*2-5,this.left+this.width/8,0,1);  //打印表格竖线
                        this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+this.width/8,this.width/8,this.height*2,"");
                        this.LODOP.ADD_PRINT_LINE(iCurLine-5,this.left+this.width/8*2,iCurLine+this.height*2-5,this.left+this.width/8*2,0,1);  //打印表格竖线
                        this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+this.width/8*2,this.width/8,this.height*3,"");
                        this.LODOP.ADD_PRINT_LINE(iCurLine-5,this.left+this.width/8*3,iCurLine+this.height*2-5,this.left+this.width/8*3,0,1);  //打印表格竖线
                        this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+this.width/8*3,this.width/8,this.height*2,"");
                        this.LODOP.ADD_PRINT_LINE(iCurLine-5,this.left+this.width/8*4,iCurLine+this.height*2-5,this.left+this.width/8*4,0,1);  //打印表格竖线
                        this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+this.width/8*4,this.width/8,this.height*3,"");
                        this.LODOP.ADD_PRINT_LINE(iCurLine-5,this.left+this.width/8*5,iCurLine+this.height*2-5,this.left+this.width/8*5,0,1);  //打印表格竖线
                        this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+this.width/8*5,this.width/8,this.height*2,"");
                        this.LODOP.ADD_PRINT_LINE(iCurLine-5,this.left+this.width/8*6,iCurLine+this.height*2-5,this.left+this.width/8*6,0,1);  //打印表格竖线
                        this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+this.width/8*6,this.width/8,this.height*2,"");
                        this.LODOP.ADD_PRINT_LINE(iCurLine-5,this.left+this.width/8*7,iCurLine+this.height*2-5,this.left+this.width/8*7,0,1);  //打印表格竖线
                        this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+this.width/8*7,this.width/8,this.height*2,"");
                        this.LODOP.ADD_PRINT_LINE(iCurLine-5,this.left+this.width,iCurLine+this.height*2-5,this.left+this.width,0,1);  //打印表格竖线
                        iCurLine=iCurLine+this.height*2;
                    }
                }


                this.printfooter(iCurLine,a);
//                this.LODOP.PREVIEW();
                this.LODOP.PRINT();
            },

            printHeader: function (a) {
                this.LODOP.SET_PRINT_STYLE("FontSize",this.contentFontSize);
                this.LODOP.SET_PRINT_STYLE("Alignment",2);
                this.LODOP.ADD_PRINT_TEXT(this.top,this.left,this.width,this.height,"销售单");
                this.LODOP.SET_PRINT_STYLEA(1,"Bold",1);

                this.LODOP.SET_PRINT_STYLE("Alignment",1);

                this.LODOP.ADD_PRINT_TEXT(this.top=this.top+this.height,this.left,this.width/2,this.height,"单据编号：" + a.sn );
                this.LODOP.ADD_PRINT_TEXT(this.top,this.left+this.width/2,this.width,this.height,"创建日期：" + a.bizdate);
                this.LODOP.ADD_PRINT_TEXT(this.top=this.top+this.height,this.left,this.width/2,this.height,"单据状态："+ this.getState(a.state).stateText );
                this.LODOP.ADD_PRINT_TEXT(this.top,this.left+this.width/2,this.width/2,this.height,"会员名称：" + a.memberName);

                this.top+=this.height;
                this.LODOP.ADD_PRINT_LINE(this.top-5,this.left,this.top-5,this.width+this.left,0,1);  //打印表格横向线
                this.LODOP.SET_PRINT_STYLE("Alignment",2);
                // LODOP.ADD_PRINT_LINE(top-5,left-5,top+height*2-5,left-5,0,1);  //打印表格竖线
                this.LODOP.ADD_PRINT_LINE(this.top-5,this.left,this.top+this.height*2-5,this.left,0,1);  //打印表格竖线
                this.LODOP.ADD_PRINT_TEXT(this.top,this.left,this.width/8,this.height*2,"序号");
                this.LODOP.ADD_PRINT_LINE(this.top-5,this.left+this.width/8,this.top+this.height*2-5,this.left+this.width/8,0,1);  //打印表格竖线
                this.LODOP.ADD_PRINT_TEXT(this.top,this.left+this.width/8,this.width/8,this.height*2,"名称");
                this.LODOP.ADD_PRINT_LINE(this.top-5,this.left+this.width/8*2,this.top+this.height*2-5,this.left+this.width/8*2,0,1);  //打印表格竖线
                this.LODOP.ADD_PRINT_TEXT(this.top,this.left+this.width/8*2,this.width/8,this.height*2,"数量");
                this.LODOP.ADD_PRINT_LINE(this.top-5,this.left+this.width/8*3,this.top+this.height*2-5,this.left+this.width/8*3,0,1);  //打印表格竖线
                this.LODOP.ADD_PRINT_TEXT(this.top,this.left+this.width/8*3,this.width/8,this.height*2,"原价(元)");
                this.LODOP.ADD_PRINT_LINE(this.top-5,this.left+this.width/8*4,this.top+this.height*2-5,this.left+this.width/8*4,0,1);  //打印表格竖线
                this.LODOP.ADD_PRINT_TEXT(this.top,this.left+this.width/8*4,this.width/8,this.height*2,"单价(元)");
                this.LODOP.ADD_PRINT_LINE(this.top-5,this.left+this.width/8*5,this.top+this.height*2-5,this.left+this.width/8*5,0,1);  //打印表格竖线
                this.LODOP.ADD_PRINT_TEXT(this.top,this.left+this.width/8*5,this.width/8,this.height*2,"金额(元)");
                this.LODOP.ADD_PRINT_LINE(this.top-5,this.left+this.width/8*6,this.top+this.height*2-5,this.left+this.width/8*6,0,1);  //打印表格竖线
                this.LODOP.ADD_PRINT_TEXT(this.top,this.left+this.width/8*6,this.width/8,this.height*2,"结算方式");
                this.LODOP.ADD_PRINT_LINE(this.top-5,this.left+this.width/8*7,this.top+this.height*2-5,this.left+this.width/8*7,0,1);  //打印表格竖线
                this.LODOP.ADD_PRINT_TEXT(this.top,this.left+this.width/8*7,this.width/8,this.height*2,"商品备注");
                this.LODOP.ADD_PRINT_LINE(this.top-5,this.left+this.width,this.top+this.height*2-5,this.left+this.width,0,1);  //打印表格竖线
                // LODOP.ADD_PRINT_LINE(top-5,left+width+5,top+height*2-5,left+width+5,0,1);  //打印表格竖线

            },
            printfooter: function (iCurLine,a) {
                this.LODOP.SET_PRINT_STYLE("Alignment",1);
                this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+5,this.width/3,this.height*2,"应收金额：" + a.receivable + "元");
                this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+5+this.width/3,this.width/3,this.height*2,"实收金额: " + (a.state==0?"该单未结算":a.received + "元"));
                this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+5+this.width/3*2,this.width/3,this.height*2,"会员余额： " + (a.memberBalance==undefined?"该单未结算":a.memberBalance + "元"));
                this.LODOP.ADD_PRINT_LINE(iCurLine-5,this.left,iCurLine-5,this.width+this.left,0,1);  //打印表格横向线
                this.LODOP.ADD_PRINT_LINE(iCurLine-5,this.left,iCurLine+this.height*2-5,this.left,0,1);  //打印表格竖线
                this.LODOP.ADD_PRINT_LINE(iCurLine-5,this.left+this.width,iCurLine+this.height*2-5,this.left+this.width,0,1);  //打印表格竖线

                iCurLine=iCurLine+this.height*2;
                this.LODOP.ADD_PRINT_TEXT(iCurLine,this.left+5,this.width,this.height,"制单人：" + a.creatorName);
                this.LODOP.ADD_PRINT_LINE(iCurLine-5,this.left,iCurLine-5,this.width+this.left,0,1);  //打印表格横向线
                this.LODOP.ADD_PRINT_TEXT(iCurLine+this.height,this.left+5,this.width,this.height*2,"打印日期：" + (new Date()).toLocaleDateString()+" "+(new Date()).toLocaleTimeString());
            }
        }
    }
</script>

<style scoped>
    .pages {
        position: fixed;
        bottom: 0;
        text-align: center;
        width: 70%;
        margin: 0 auto;
        /* background: black; */
        z-index: 20;
        height: 20px;
        opacity: 0.5;
        font-size: 9px;
    }

    .item {
        position: absolute;
        top: 5px;
        left: 5px;
        right: 5px;
        bottom: 5px;
        font-size: 1.2em;
        color: rgb(0, 158, 107);
    }

    .list-main {
        padding-top: 80px;
    }

    .spec {
        font-size: 1em;
        border: none;
        left: 0;
        padding: 0;
    }

    .part1 {
        padding-bottom: 5px;
        border-bottom: 1px solid #cacaca;
    }

    .pd10 {
        padding: 10px 0px 0px 20px;
    }

    .l1 {
        text-indent: initial;
        margin-top: -24px;
    }

    .el-button.item {
        position: static;
    }
    #myDIV{
        margin: 0 20px;
    }
</style>
